/**
 * Copyright (C) 2008 aileron.cc
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package cc.aileron.commons.exception;

/**
 * アクセサが存在しない際の例外
 * 
 * @author aileron
 * 
 */
public class NoSuchAccessorRuntimeException extends RuntimeException
{
    /**
     * メソッド種別
     * 
     * @author aileron
     */
    public static enum MethodType
    {
        /**
         * GET
         */
        GET,

        /**
         * SET
         */
        SET
    }

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = -5184946454022677603L;

    /**
     * 例外メッセージを組みたてる
     * 
     * @param method
     * @param target
     * @param name
     * @param value
     * @return
     */
    private static String createMessage(final MethodType method,
            final Class<?> target,
            final String name,
            final Object value)
    {
        return "pojo-accessor @ " + target.getName() + " : " + method + " # "
                + name + "(" + (value != null ? value.getClass() : "") + ")"
                + " is not found !!!";
    }

    /**
     * target を クラスで指定した際の例外の生成
     * 
     * @param method
     * @param target
     * @param name
     * @param value
     */
    public NoSuchAccessorRuntimeException(
        final MethodType method,
        final Class<?> target,
        final String name,
        final Object value)
    {
        super(createMessage(method, target, name, value));
    }

    /**
     * target を インスタンスで指定した際の例外の生成
     * 
     * @param method
     * @param target
     * @param name
     * @param value
     */
    public NoSuchAccessorRuntimeException(
        final MethodType method,
        final Object target,
        final String name,
        final Object value)
    {
        super(createMessage(method, target.getClass(), name, value));
    }
}